package xyz.yuanjilu.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import xyz.yuanjilu.entity.GroupSalesEntity;
import xyz.yuanjilu.service.GroupSalesService;
import xyz.yuanjilu.utils.PageUtils;
import xyz.yuanjilu.utils.Query;
import xyz.yuanjilu.utils.R;


/**
 * 群组销售管理
 * 
 * @author CHENJUNFEI
 * @email kkomge@qq.com
 * @date 2017-07-19 14:54:21
 */
@RestController
@RequestMapping("groupsales")
public class GroupSalesController {
	@Autowired
	private GroupSalesService groupSalesService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("groupsales:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);

		List<GroupSalesEntity> groupSalesList = groupSalesService.queryList(query);
		int total = groupSalesService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(groupSalesList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	@RequiresPermissions("groupsales:info")
	public R info(@PathVariable("id") Long id){
		GroupSalesEntity groupSales = groupSalesService.queryObject(id);
		
		return R.ok().put("groupSales", groupSales);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("groupsales:save")
	public R save(@RequestBody GroupSalesEntity groupSales){
		groupSalesService.save(groupSales);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("groupsales:update")
	public R update(@RequestBody GroupSalesEntity groupSales){
		groupSalesService.update(groupSales);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("groupsales:delete")
	public R delete(@RequestBody Long[] ids){
		groupSalesService.deleteBatch(ids);
		
		return R.ok();
	}
	
}
